Unit SpeedTestWin;

Interface

 Uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, TeEngine, ExtCtrls, TeeProcs, Chart, StdCtrls, Series;

 Type
  TForm1 = Class(TForm)
   Chart1: TChart;
   Button1: TButton;
   Procedure Button1Click(Sender: TObject);

   Private
    { Private declarations }
   Public
    { Public declarations }
  END;

 Var
  Form1: TForm1;

Implementation

{$R *.dfm}

 Uses
  MMSystem, ActiveX,
  Generics.Collections,
  JumboDictionary;

 Type
  TTestRec = Record
   ID: Cardinal;
   Name: String;
   Ptr1, Ptr2: Pointer;
   Flags: Array [0 .. 6] of Byte;
  END; // Just some synthetic payload...

  TDephiDict = TDictionary<String, TTestRec>;
  TJumboDict = TJumboDictionary<String, TTestRec>;

 Procedure TForm1.Button1Click(Sender: TObject);
  Var
   DelphiDict: TDephiDict;
   JumboDict: TJumboDict;
   WorkingSeries: TLineSeries;
   Index: Cardinal;
   GUIDKey: TGUID;
   Key: String;
   TestRec: TTestRec;
   SafeMem: TBytes; // Reserved some memory before trying to exaust it
   Latency: Cardinal;
  BEGIN
   Button1.Hide;
   Chart1.Show;
   Application.ProcessMessages;

   FillChar(TestRec, Sizeof(TTestRec), 0);

   // Test Delphi Dictionary
   WorkingSeries:= TLineSeries.Create(Chart1);
   WorkingSeries.Title:= 'Delphi';
   Chart1.AddSeries(WorkingSeries);

   SetLength(SafeMem, $10000);
   Latency:= timeGetTime;
   DelphiDict:= TDephiDict.Create;
   Try
    For Index:= 0 to $10000000 do
     BEGIN
      CoCreateGuid(GUIDKey);
      Key:= GUIDToString(GUIDKey);
      TestRec.ID:= Index;
      IF (Index AND $FFFF) = 0 then
       BEGIN
        Latency:= timeGetTime - Latency;
        WorkingSeries.AddXY(Index, Latency);
        Application.ProcessMessages;
        Latency:= timeGetTime;
       END;
      DelphiDict.Add(Key, TestRec);
     END;
   Except
    // Release reserved memory
    SetLength(SafeMem, 0);
    DelphiDict.Free;
   END;

   // Test Jumbo Dictionary
   WorkingSeries:= TLineSeries.Create(Chart1);
   WorkingSeries.Title:= 'Jumbo Split-1';
   Chart1.AddSeries(WorkingSeries);

   SetLength(SafeMem, $10000);
   Latency:= timeGetTime;
   JumboDict:= TJumboDict.Create(1);
   Try
    For Index:= 0 to $10000000 do
     BEGIN
      CoCreateGuid(GUIDKey);
      Key:= GUIDToString(GUIDKey);
      TestRec.ID:= Index;
      IF (Index AND $FFFF) = 0 then
       BEGIN
        Latency:= timeGetTime - Latency;
        WorkingSeries.AddXY(Index, Latency);
        Application.ProcessMessages;
        Latency:= timeGetTime;
       END;
      JumboDict.Add(Key, TestRec);
     END;
   Except
    // Release reserved memory
    SetLength(SafeMem, 0);
    JumboDict.Free;
   END;

   // Test Jumbo Dictionary
   WorkingSeries:= TLineSeries.Create(Chart1);
   WorkingSeries.Title:= 'Jumbo Split-2';
   Chart1.AddSeries(WorkingSeries);

   SetLength(SafeMem, $10000);
   Latency:= timeGetTime;
   JumboDict:= TJumboDict.Create(2);
   Try
    For Index:= 0 to $10000000 do
     BEGIN
      CoCreateGuid(GUIDKey);
      Key:= GUIDToString(GUIDKey);
      TestRec.ID:= Index;
      IF (Index AND $FFFF) = 0 then
       BEGIN
        Latency:= timeGetTime - Latency;
        WorkingSeries.AddXY(Index, Latency);
        Application.ProcessMessages;
        Latency:= timeGetTime;
       END;
      JumboDict.Add(Key, TestRec);
     END;
   Except
    // Release reserved memory
    SetLength(SafeMem, 0);
    JumboDict.Free;
   END;

   // Test Jumbo Dictionary
   WorkingSeries:= TLineSeries.Create(Chart1);
   WorkingSeries.Title:= 'Jumbo Split-4';
   Chart1.AddSeries(WorkingSeries);

   SetLength(SafeMem, $10000);
   Latency:= timeGetTime;
   JumboDict:= TJumboDict.Create(4);
   Try
    For Index:= 0 to $10000000 do
     BEGIN
      CoCreateGuid(GUIDKey);
      Key:= GUIDToString(GUIDKey);
      TestRec.ID:= Index;
      IF (Index AND $FFFF) = 0 then
       BEGIN
        Latency:= timeGetTime - Latency;
        WorkingSeries.AddXY(Index, Latency);
        Application.ProcessMessages;
        Latency:= timeGetTime;
       END;
      JumboDict.Add(Key, TestRec);
     END;
   Except
    // Release reserved memory
    SetLength(SafeMem, 0);
    JumboDict.Free;
   END;

   // Test Jumbo Dictionary
   WorkingSeries:= TLineSeries.Create(Chart1);
   WorkingSeries.Title:= 'Jumbo Split-8';
   Chart1.AddSeries(WorkingSeries);

   SetLength(SafeMem, $10000);
   Latency:= timeGetTime;
   JumboDict:= TJumboDict.Create(8);
   Try
    For Index:= 0 to $10000000 do
     BEGIN
      CoCreateGuid(GUIDKey);
      Key:= GUIDToString(GUIDKey);
      TestRec.ID:= Index;
      IF (Index AND $FFFF) = 0 then
       BEGIN
        Latency:= timeGetTime - Latency;
        WorkingSeries.AddXY(Index, Latency);
        Application.ProcessMessages;
        Latency:= timeGetTime;
       END;
      JumboDict.Add(Key, TestRec);
     END;
   Except
    // Release reserved memory
    SetLength(SafeMem, 0);
    JumboDict.Free;
   END;

   // Test Jumbo Dictionary
   WorkingSeries:= TLineSeries.Create(Chart1);
   WorkingSeries.Title:= 'Jumbo Split-16';
   Chart1.AddSeries(WorkingSeries);

   SetLength(SafeMem, $10000);
   Latency:= timeGetTime;
   JumboDict:= TJumboDict.Create(16);
   Try
    For Index:= 0 to $10000000 do
     BEGIN
      CoCreateGuid(GUIDKey);
      Key:= GUIDToString(GUIDKey);
      TestRec.ID:= Index;
      IF (Index AND $FFFF) = 0 then
       BEGIN
        Latency:= timeGetTime - Latency;
        WorkingSeries.AddXY(Index, Latency);
        Application.ProcessMessages;
        Latency:= timeGetTime;
       END;
      JumboDict.Add(Key, TestRec);
     END;
   Except
    // Release reserved memory
    SetLength(SafeMem, 0);
    JumboDict.Free;
   END;
  END;

END.
